package com.yami.shop.rights.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.rights.common.dao.ProdRightsExternalDataMapper;
import com.yami.shop.rights.common.dto.RightsExternalExcelDto;
import com.yami.shop.rights.common.model.ProdRightsExternalData;
import com.yami.shop.rights.common.service.ProdRightsExternalDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProdRightsExternalDataServiceImpl extends ServiceImpl<ProdRightsExternalDataMapper, ProdRightsExternalData> implements ProdRightsExternalDataService {

    @Autowired
    private ProdRightsExternalDataMapper prodRightsExternalDataMapper;

    @Override
    public List<ProdRightsExternalData> getDataByCount(String prodId, long drawCount) {
        QueryWrapper<ProdRightsExternalData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("external_id",prodId);
        queryWrapper.eq("status","0");
        queryWrapper.last("limit "+drawCount);
        List<ProdRightsExternalData> list = this.list(queryWrapper);
        list.forEach(s->{
            s.setStatus(1);
        });
        this.updateBatchById(list);
        return list;
    }

    @Override
    public List<RightsExternalExcelDto> excelExternalRecord(Long id) {
        return prodRightsExternalDataMapper.excelExternalRecord(id);
    }
}
